package com.wm.wmcrm.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wm.wmcrm.sys.entity.SysMenu;
import com.wm.wmcrm.sys.mapper.SysMenuMapper;
import com.wm.wmcrm.sys.service.ISysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单管理 服务实现类
 * </p>
 *
 * @author wm
 * @since 2023-02-11
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {

    @Override
    public List<SysMenu> selectList() {
        LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<SysMenu>()
                .eq(true,SysMenu::getParentId,0);
        List<SysMenu> sysMenus = this.baseMapper.selectList(wrapper);
        for(SysMenu sysMenu :sysMenus){
            LambdaQueryWrapper<SysMenu> wrapper1 = new LambdaQueryWrapper<SysMenu>()
                    .eq(true,SysMenu::getParentId,sysMenu.getMenuId());
            List<SysMenu> sysMenuC = this.baseMapper.selectList(wrapper1);
            if(!sysMenuC.isEmpty()){
                sysMenu.setChildren(sysMenuC);
            }
        }
        return sysMenus;
    }
}
